package com.ad2campaign.engine.rest;

import java.net.URLEncoder;

import org.apache.log4j.Logger;
/*
 * This class represent's a key and encoded value pair.
 * It will pass through restful operation 
 * */
public class RequestParameter 
{
	private static final Logger LOGGER =  Logger.getLogger(RequestParameter.class);
	private String paramName;
	private String paramvalue;
	
	public String getParamName() 
	{
		return paramName;
	}
	public void setParamName(String paramName)
	{
		this.paramName = paramName;
	}
	public String getParamvalue()
	{
		return paramvalue;
	}
	public void setParamvalue(String paramvalue) 
	{
		try 
		{
			this.paramvalue = URLEncoder.encode(paramvalue, "UTF-8");
 		} 
		catch (Exception e) 
 		{
 			LOGGER.warn("Invalid value of param ["+getParamName()+"] is supplied ["+paramvalue+", Passing empty string for this param ]");
 	 		LOGGER.debug("Invalid value of param ["+getParamName()+"] is supplied ["+paramvalue+"]",e);
 	 		this.paramvalue="";
 	 	}
	}
	@Override
	public String toString() 
	{
		return paramName+"="+paramvalue;
 	}
	public RequestParameter(String paramName, String paramvalue) {
		super();
		this.paramName = paramName;
		try 
		{
			this.paramvalue = URLEncoder.encode(paramvalue, "UTF-8");
 		} 
		catch (Exception e) 
 		{
 			LOGGER.warn("Invalid value of param ["+getParamName()+"] is supplied ["+paramvalue+", Passing empty string for this param ]");
 	 		LOGGER.debug("Invalid value of param ["+getParamName()+"] is supplied ["+paramvalue+"]",e);
 	 		this.paramvalue="";
 	 	}
	}
	
}
